/**
 * Created by gongxun on 17/1/13.
 */

var PszCardHelper = function(){
    var that = {};

    that.design = cc.size(116, 160);

    that.inhandScale = 1;

    that.inhandMyScale = 1;

    that.cardWellScale = 1;

    //玩家座位位置
    that.seats = null;

    //玩家手牌位置
    that.seatCards = null;

    //牌墙位置
    that.cardWellPoint = null;

    //筹码位置
    that.chipRect = null;

    that.init = function(){
        that.inhandScale = 0.42;
        that.inhandMyScale = 0.85;
        that.cardWellScale = 0.3;

        that.cardWellPoint = cc.p(mo.gameSize.x / 2, mo.gameSize.y - 200);
        that.chipRect = cc.rect(380, 320, mo.gameSize.x - 760, 150);
    };

    //设置相关位置
    that.initSeats = function(seats, seatCards){
        that.seats = seats;
        that.seatCards = seatCards;
    };

    that.getCardSize = function(){
        var size = cc.size(that.design.width * that.inhandScale, that.design.height * that.inhandScale);
        return size;
    };

    that.getMyCardSize = function(){
        var size = cc.size(that.design.width * that.inhandMyScale, that.design.height * that.inhandMyScale);
        return size;
    };

    //返回手牌位置
    that.getInhandCardPos = function(seat, index){
        var offset = 0;
        var cardSize = cc.size(0, 0);
        if (seat == 0){
            offset = 40;
            cardSize = that.getMyCardSize();
        }else{
            offset = 27;
            cardSize = that.getCardSize();
        }

        var centerP = cc.p(that.seatCards[seat].x, that.seatCards[seat].y);
        var x = (index - 1) * offset + centerP.x;
        var y = centerP.y + cardSize.height / 2;
        return cc.p(x, y);
    };

    //返回表情序列帧
    that.getFaceFrames = function (index) {
        var spriteFrames = [];
        for (var i = 0; i <= 60; i++){
            var frame = cc.spriteFrameCache.getSpriteFrame("emoji_" + index + "_" + i + ".png");
            if (frame == null){
                break;
            }
            spriteFrames.push(frame);
        }
        return spriteFrames;
    };

    //返回合法
    that.getExistCardNum = function (cardNum) {
        if (cardNum >= 1 && cardNum <= 54){
            return true;
        }
        return false;
    };

    that.getRandomCard = function(size){
        var result = [];
        for (var i = 0; i < size; i++){
            result.push(parseInt(Math.random() * 54) + 1);
        }
        return result;
    };

    that.getRandomCardType = function(){
        return parseInt(Math.random() * 7);
    };

    //返回chip位置
    that.getRandomChipPoint = function(){
        var x = cc.rectGetMinX(that.chipRect) + Math.random() * that.chipRect.width;
        var y = cc.rectGetMinY(that.chipRect) + Math.random() * that.chipRect.height;
        return cc.p(x, y);
    };

    //返回牌型对应的中文
    that.getCardTypeCHS = function(cardType){
        var types = [
            "豹子",
            "顺金",
            "金花",
            "顺子",
            "对子",
            "单张",
            "三条",
            "235",
            "匿名"
        ];

        return types[cardType];
    };

    return that;
};

mo.pszCardHelper = new PszCardHelper();